# -*- coding: utf-8 -*-
# @File: mail.py
# @Author: Liccsu
# @Time: 12/8/2022 下午3:11
# @Project: eschool-health

import yagmail

try:
    from cfg import Cfg
except ModuleNotFoundError or ImportError:
    from .cfg import Cfg


class EMail:
    def __init__(self):
        self.user: str = Cfg.send_mail
        self.password: str = Cfg.mail_key
        self.host: str = Cfg.mail_host

    def send_email(self, address: str, title: str, content: str):
        try:
            mail_server = yagmail.SMTP(
                user=self.user,
                password=self.password,
                host=self.host
            )
            mail_server.send(
                address,
                title,
                content,
                attachments=None
            )
            mail_server.close()
        except Exception:
            raise


if __name__ == '__main__':
    em = EMail()
    print(em)
